﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GodPl.Exceptions;
using GodPl.GameObjects.Creatures;
using GodPl.WorldState;

namespace GodPl.GameObjects.Creatures.Actions
{
    public class ABreedWith : BriyyaAction
    {
        static readonly TimeSpan minDuration = new TimeSpan(0, 0, 10);
        static readonly TimeSpan maxDuration = new TimeSpan(0, 0, 10);


        public ABreedWith(Briyya actor, Briyya target)
            : base(actor, target)
        {
            assertTarget();
        }

        public override void Begin()
        {
            base.Begin();

            Briyya partner = (Briyya)target;

            if (partner.Sex == actor.Sex ||
                Math.Min(partner.Drives[DriveName.SexDrive], partner.Drives[DriveName.SexDrive]) < 0.75f)
            {
                Finish();
                return;
            }

            actor.Drives[DriveName.SexDrive] -= 0.75f;
            partner.BeBredWith();

            Genes genes = Genes.Recombine(actor.Genes, partner.Genes);
            Briyya child = new Briyya(actor.World, actor.World.GetRandomLocation(), genes);
            actor.World.AddObject(child);

            Finish();
            
        }


        protected override TimeSpan MinDuration
        {
            get { return minDuration; }
        }

        protected override TimeSpan MaxDuration
        {
            get { return maxDuration; }
        }
    }
}
